package cn.zswltech.gruul.auth;

import cn.zswltech.gruul.common.entity.DisplayMenuTreeDO;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Jim
 * @version 1.0.0
 * @descripition:
 * @date 2024/2/2 14:10
 */
@Service
@Slf4j
public abstract class AbstractAuthChecker implements ApplicationAuthChecker {

    public void print(HttpServletResponse response, Object message, int httpCode) {
        try {
            response.setStatus(httpCode);
            response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
            response.setHeader("Cache-Control", "no-cache, must-revalidate");
            PrintWriter writer = response.getWriter();
            writer.write(JSON.toJSONString(message));
            writer.flush();
            writer.close();
        } catch (IOException e) {
            log.error("error:", e);
        }
    }
}
